var BaseUrl = "http://47.102.45.219:8080/Appoint/Appoint/FeastSecServlet/"



//判断码
var isDel = 0
var vm = new Vue({
	el: "#fea_info",
	data: {
		msgList: getFeastPage()
	},
	methods: {
		delMsg: function () {
			vm.msgList = allFun()
		},
		setId: function (index) {
			return "td_" + index
		},
		setAId: function (index) {
			return "a_" + index
		},
		getVal: function (val) {
			if (isDel == 0) {
				layer.confirm('改成未审核状态？', function () {
					delFeast(val)
					layer.msg('修改成功!', {
						icon: 1,
						time: 1000
					});
				})
			} else {
				layer.confirm('是否通过审核?', function () {
					rollbackFeast(val)
					layer.msg('操作成功', {
						icon: 1,
						time: 1000
					})
				})
			}
			//alert(val)
		},
		getMsg: function (val) {
			xadmin.open('详情', './feast-add.html?id=' + val, 600, 400)
			//alert(val)
		},
		updateVal: function (val) {
			xadmin.open('编辑', 'feast-edit.html?id=' + val, 650, 480)
		}
	}
})

//查询所有饭局
function getAllFeast() {

	var counts

	$.ajax({
		url: BaseUrl + "/selectAllFeast",
		data: {},
		success: function (data) {
			if (data.statu) {
				flist = data.data
				counts = flist.length
				initData(counts)
				$("#deleteID").text("查看待审核饭局")
				isDel = 0
				//alert(isDel)
			} else {
				$("#deleteID").text("查看待审核饭局")
				isDel = 0
			}
		},
		dataType: "json",
		type: 'post',
		statusCode: {
			404: function () {
				alert('page not found');
			}
		},
		xhrFields: {
			withCredentials: true
		},
		async: false
	})
	return counts
}

//分页查询饭局
function getFeastPage() {
	var flist

	$.ajax({
		url: BaseUrl + "/selectAllFeastPage",
		data: {
			"pageIndex": _pageIndex,
			"pageSize": _pageSize
		},
		success: function (data) {
			if (data.statu) {
				flist = data.data
				var allNum = getAllFeast()
				initData(allNum)
				$("#deleteID").text("查看待审核饭局")
				isDel = 0
			} else {
				$("#deleteID").text("查看待审核饭局")
				initData(1)
				isDel = 0
			}
		},
		dataType: "json",
		type: 'post',
		statusCode: {
			404: function () {
				alert('page not found');
			}
		},
		xhrFields: {
			withCredentials: true
		},
		async: false
	})
	return flist
}

//查询已删除饭局
function getDelFeast() {

	var counts

	$.ajax({
		url: BaseUrl + "/selectAllFeastDel",
		data: {},
		success: function (data) {
			if (data.statu) {
				flist = data.data
				counts = flist.length
				initData(counts)
				$("#deleteID").text("查看已审核饭局")
				isDel = 1
			} else {
				$("#deleteID").text("查看已审核饭局")
				isDel = 1
			}
		},
		dataType: "json",
		type: 'post',
		statusCode: {
			404: function () {
				alert('page not found');
			}
		},
		xhrFields: {
			withCredentials: true
		},
		async: false
	})
	return counts
}

//分页查询已删除饭局
function getDelFeastPage() {
	var flist

	$.ajax({
		url: BaseUrl + "/selectAllFeastPageDel",
		data: {
			"pageIndex": _pageIndex,
			"pageSize": _pageSize
		},
		success: function (data) {
			if (data.statu) {
				flist = data.data
				var delNum = getDelFeast()
				initData(delNum)
				$("#deleteID").text("查看已审核饭局")
				isDel = 1
			} else {
				$("#deleteID").text("查看已审核饭局")
				initData(1)
				isDel = 1
			}
		},
		dataType: "json",
		type: 'post',
		statusCode: {
			404: function () {
				alert('page not found');
			}
		},
		xhrFields: {
			withCredentials: true
		},
		async: false
	})
	return flist
}

//增加饭局



//删除饭局
function delFeast(fid) {


	$.ajax({
		url: BaseUrl + "/deleteFeast",
		data: {
			"fid": fid
		},
		success: function (data) {
			if (data.statu) {
				vm.msgList = getFeastPage()
			}
		},
		dataType: "json",
		type: 'post',
		statusCode: {
			404: function () {
				alert('page not found');
			}
		},
		xhrFields: {
			withCredentials: true
		},
		async: false
	})

}
//总方法
function allFun() {
	var flist
	if ($("#deleteID").text() == "查看已审核饭局") {
		flist = getFeastPage()
	} else {
		flist = getDelFeastPage()
	}
	return flist
}
//批量删除
//分页
function initData(list_length) {
	initPagin(list_length, "page")
	createRollLoad()
}

//撤销删除的饭局 backDelByAdmin
function rollbackFeast(fid) {
	$.ajax({
		url: BaseUrl + "/backDelByAdmin",
		data: {
			"fid": fid
		},
		success: function (data) {
			if (data.statu) {
				vm.msgList = getDelFeastPage()
			}
		},
		dataType: "json",
		type: 'post',
		statusCode: {
			404: function () {
				alert('page not found');
			}
		},
		xhrFields: {
			withCredentials: true
		},
		async: false
	})
}